//描述某个像素块的类别（显示状态）
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum IsWhat {
    Framel,          //左边'-|'
    Framer,          //右边'|-'
    Framey,          //上下边'--'
    Block,           //空白'  '
    Head,            //蛇头'头'
    Body,            //蛇身'身'
    Tail,            //蛇尾'尾'
    Food,            //食物'果'
}
pub trait What {}
impl What for IsWhat{}

impl IsWhat {
    //打印块
    pub fn print(&self) {
        match self {
            IsWhat::Framel => {print!("-|");}
            IsWhat::Framer => {print!("|-");}
            IsWhat::Framey => {print!("==");}
            IsWhat::Block => {print!("  ");}
            IsWhat::Head => {print!("头");}
            IsWhat::Body => {print!("身");}
            IsWhat::Tail => {print!("尾");}
            IsWhat::Food => {print!("硫");}
        }
    }
}
//描述某个像素块下一步的移动方向
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Direction {
    Left,         //左
    Right,        //右
    Up,           //上
    Down,         //下
    Stop,         //停
}
pub trait Way {}
impl Way for Direction {}
impl Direction {
    pub fn get_direction(&self) -> i32 {
        match self {
            Direction::Left => 1,
            Direction::Right => 3,
            Direction::Up => 2,
            Direction::Down => 4,
            Direction::Stop => 5,
        }
    }
}
//描述蛇的下一步行为
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Todo {
    Move,           //移动
    Grow,           //生长
    Die,            //死亡
}

//转换为方向枚举值
pub fn to_direction(x:i32) -> Direction {
    match x {
        1 => Direction::Left,
        3 => Direction::Right,
        2 => Direction::Up,
        4 => Direction::Down,
        _ => Direction::Stop
    }
}
//取绝对值
pub fn abs (x:i32) -> i32 {
    if x >= 0 {
        x
    }else {
        -x
    }
}